package org.example.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.example.Manager.ProductManager;
import org.example.model.ProductDO;
import org.example.service.ProductService;
import org.example.vo.ProductVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 谢超
 * @since 2024-03-21
 */
@Service
@Slf4j
public class ProductServiceImpl implements ProductService {

    @Resource
    private ProductManager productManager;

    /**
     *  获取商品列表
     * @return
     */
    @Override
    public List<ProductVO> getList() {
        List<ProductDO> list = productManager.getList();
        return list.stream().map(this::beanProcess).collect(Collectors.toList());
    }

    @Override
    public ProductVO getDetail(long productId) {
        ProductDO productDO = productManager.getDetail(productId);
        return beanProcess(productDO);
    }

    private ProductVO beanProcess(ProductDO productDO) {
        ProductVO productVO = new ProductVO();

        BeanUtils.copyProperties(productDO , productVO);

        return productVO;
    }
}
